package com.itqf.service.impl;

import com.itqf.dao.AddressDao;
import com.itqf.dao.impl.AddressDaoImpl;
import com.itqf.entity.Address;
import com.itqf.service.AddressService;

import java.sql.SQLException;
import java.util.List;

public class AddressServiceImpl implements AddressService {

    //初始化dao层对象
    private static AddressDao addressDao = new AddressDaoImpl();

    @Override
    public List<Address> findAddressByUid(int uid) throws SQLException {

        //调用dao层进行数据访问操作
        List<Address> list = addressDao.selectAddressByUid(uid);

        return list;
    }

    @Override
    public void saveAddress(Address address) throws SQLException {

        //调用dao层进行数据访问操作
        addressDao.insertAddress(address);

    }

    @Override
    public void deleteAddressByAid(String aid) throws SQLException {

        addressDao.deleteAddressByAid(aid);
    }

    @Override
    public void setAddressToDefult(String aid , int uid) throws SQLException {

        //1.将aid地址的默认地址状态改为1
        addressDao.updateAddressToDefult(aid);

        //2.将aid地址的默认地址状态改为0
        addressDao.updateAddressToCommons(aid ,uid);
    }

    @Override
    public void updateAddressByAid(Address address) throws SQLException {

        addressDao.updateAddressByAid(address);
    }
}
